'use strict'

class MenuService {
  
  menu_merge(menu_list = [],pid = ''){
    var arr = [];
    menu_list.forEach((v, index) => {
      if(v['parent_code'] == pid){ 
          v['children'] = this.menu_merge(menu_list,v['code']);
          arr.push(v);
        }
    });
    if(arr.length <= 0) return null;
    else return arr;
  }

  menu_path(menu_list = [],path = '',arr=[]){
    menu_list.forEach((v, index) => {
      arr.push(path + v['path']);
      if(v['children'] && v['children'] != undefined && v['children'].length > 0){ 
          v['path'] = path + v['path'] + '/'
          this.menu_path(v['children'],v['path'],arr);
        }
    });
    if(arr.length <= 0) return null;
    else return arr;
  }

}

module.exports = new MenuService();